package com.itgungnir.designpattern.mediator;

import java.util.ArrayList;
import java.util.List;

public class ChatRoom {
	private List<User> users;

	public ChatRoom() {
		System.out.println("聊天室开启！！");
		users = new ArrayList<User>();
	}

	public void addUser(User user) {
		System.out.println(user.getName() + "加入了聊天室！");
		users.add(user);
	}

	public void operateMessage(Message message) {
		User fromUser = message.getFromUser();
		for (User user : users) {
			if (fromUser != user) {
				System.out.println(user.getName() + "收到了来自" + fromUser.getName() + "的消息：" + message.getContent());
			}
		}
	}
}